<?php

//set error reporting
error_reporting(E_ERROR | E_WARNING);

class HTMLFunctions{
	
	//function to print the head of an html site
	public static function printHTMLHead($title){
		
		echo "<html><head><title>$title</title>";
		echo "<link href=\"style.css\" type= \"text/css\" rel=\"stylesheet\" />";
		echo "</head><body>";
	}
	
	//function to print the head content of the site
	public static function printTitles($subTitle, $message){
		
		print <<<END_HTML
		<div class="titles">
		<h1>Online Portfolio Management</h1>
		<h2>$subTitle</h2>
		</div><!--titles-->
		<h3>$message</h3>		
END_HTML;
	}
	
	public static function generateTitleBar($subTitle, $email, $db){
		
		//create an array containing only the username key/value pair to be passed to the button creation subroutine
		$parameterArray;
		$parameterArray['email'] = $email;
		
		//obtain general user info from DB
		$porftolio = $db->getPortfolioStocks($email);
		$interest = $db->getInterestStocks($email);
		
		//declare scalars to hold most important information
		$tempInfo = $db -> getCustomerDetails($email);
		$firstName = $tempInfo['FIRST_NAME'];
		$lastName = $tempInfo['LAST_NAME'];
		$portfolioSize = count($porftolio);
		$interestSize = count($interest); //get interest
		$currentValue = $db->getCurrentPortfolioValue($email);
		$overallChange= $db->getOverallPortfolioChange($email); //get overall change
		$liquidBalance = $db->getLiquidBalance($email);
		
		//create the main outer table, subtables to be filled by further subroutines 
		//this html code is split up into bits so that respecitve subroutines can be called at the correct times
		echo <<<END_HTML
	
		<div class="header">
		<div class="titles">
		<h1>Online Portfolio Management</h1>
		</div>
	
		<!--titles-->
		<h2>$subTitle</h2>
	
		<h3>Logged in as $firstName $lastName </h3>
	
		<table class="tableheader">
		<tr class="trheader">
		<td class="tdheaderleft">
	
		<!--general stats-->
		<p>Own $portfolioSize stocks | Interested in $interestSize stocks | Overall Value: $currentValue | Overall Change: $overallChange | Balance: $liquidBalance</p></td>
	
		<!--now display the main navigation buttons-->
		<td class="tdheaderright">
		<table class="googletablebuttons1" cellpadding="0" cellspacing="0" style="float:right;">
		<tr class="googletrbuttons1">
		<td>
END_HTML;

	//now call a subroutine to print the html code for a button as well as providing the script with the necessary information
	HTMLFunctions::generateButton("updateUser.php", "Edit User Information", $parameterArray);
	
	//proceed with the table tags
	echo "</td><td>";
	
	//button for uploading funds
	HTMLFunctions::generateButton("uploadFunds.php", "Upload Funds", $parameterArray);
	
	//proceed with the table tags
	echo "</td><td>";
	
	//button for searching for a stock
	HTMLFunctions::generateButton("searchStocks.php", "Search For Stocks", $parameterArray);
	
	//use the block print for the following code
	echo <<<END_HTML
	<td>
	<!--also add logout button-->
	<form method="LINK" action="login.php"><input type="submit" value="Logout"></form>
	</td>
	</td>
	</tr>
	</table>
	</td>
	</tr>
	</table>	
	</div><!-- end of header of the profile header-->
	
END_HTML;
	}
	
	//function to print the footer of the html sites
	public static function printHTMLEnd(){
		
		echo "<div class=\"footer\">";
		echo "Created by Jennifer Hwang and Thomas Rantasa";
		echo "</div>";
		echo "</body></html>";
	}
	
	//function to create a button with specific hidden parameters used to pass information to scripts
	public static function generateButton($target, $text, $parameters){
		
		//print the beginning of the form
		echo "<form action=\"".$target."\" method=POST>";
		
		//loop through parameters and print as hidden fields
		foreach($parameters as $key => $value){
			
			//print hidden field
			echo "<input type=\"hidden\" name=\"".$key."\" value=\"".$value."\">";
		}
		
		//now print the submit button and the end of form tag
		echo "<input type=\"submit\" value=\"".$text."\"></form>";
	}
}

?>